package hello;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by yuan on 2017/9/11.
 */
@Controller
public class GreetingController {

    @RequestMapping("/greeting1")
    @ResponseBody
    public String greeting1(@RequestParam(value="name", defaultValue = "world", required = false)String name,
                            Model model){
        model.addAttribute("name", name);
        return "Content";
    }

    @RequestMapping("/greeting")
    @ResponseBody
    public Student greeting(@RequestParam(value="name", defaultValue = "world", required = false)String name,
                            Model model){
        model.addAttribute("name", name);
        return new Student(14, "lili");
    }
}

class Student{
    private int age;
    private String name;

    public Student(){}
    public Student(int age, String name){
        age = age;
        name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
